<?php


namespace App\Http\Controllers\applets\validate;


use Illuminate\Support\Facades\Validator;

class UserInfo
{


    public static function getLoginCode($param){
        $rules = [
            'phone'=> ['required','regex:/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/'],
        ];

        $msg = [
            'phone.required'=>'手机号为空',
            'phone.regex'=>'必须为手机号格式',
        ];
        return Validator::make($param,$rules,$msg)->errors()->all();
    }

    public static function codeLogin($param){
        $rules = [
            'phone'=>['required','regex:/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/'],
            'code'=>'required|numeric',
            'type_id'=>'required',
            'lastIp'=>'required|ip'
        ];
        $msg = [
            'phone.required'=>'手机号为空',
            'phone.regex'=>'必须为手机号格式',
            'type_id.required'=>'类型不能为空',
            'code.required'=>'验证码不能为空',
            'code.numeric'=>'验证码必须为数字',
            'lastIp.required'=>'IP地址为空',
            'lastIp.ip'=>'IP地址格式不对',
        ];
        return Validator::make($param,$rules,$msg)->errors()->all();
    }

    public static function register($param){
        $rules = [
            'phone'=>['required','regex:/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/'],
            'code'=>'required|numeric',
            'password'=>'required|between:6,16',
            'password2'=>'required|between:6,16',
            'lastIp'=>'required|ip'
        ];
        $msg = [
            'phone.required'=>'手机号为空',
            'phone.regex'=>'必须为手机号格式',
            'code.required'=>'验证码不能为空',
            'code.numeric'=>'验证码必须为数字',
            'password.required'=>'密码不能为空',
            'password.between'=>'密码必须大于6位小于等于16位',
            'password2.required'=>'确认密码不能为空',
            'password2.between'=>'确认密码必须大于6位小于等于16位',
            'lastIp.required'=>'IP地址为空',
            'lastIp.ip'=>'IP地址格式不对',
        ];
        return Validator::make($param,$rules,$msg)->errors()->all();
    }

    public static function getUserInfo($param){
        $rules = [
            'id'=>'required|numeric'
        ];

        $msg = [
            'id.required'=>'用户编号为空',
            'id.numeric'=>'用户编号格式不对'
        ];
        return Validator::make($param,$rules,$msg)->errors()->all();
    }

    public static function editMobile($param){
        $rules = [
            'userId'=>'required|numeric',
            'lastIp'=>'required|ip',
            'mobile'=>['required','regex:/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/'],
            'code'=>'required',
            'id'=>'required|numeric'
        ];

        $msg = [
            'userId.required'=>'用户编号为空',
            'userId.numeric'=>'用户编号格式不对',
            'lastIp.required'=>'IP地址为空',
            'lastIp.ip'=>'IP地址格式不对',
            'mobile.required'=>'手机号为空',
            'mobile.regex'=>'手机号格式不对',
            'code.required'=>'验证码为空',
            'id.required'=>'设备编号为空',
            'id.numeric'=>'设备编号格式不对'
        ];
        return Validator::make($param,$rules,$msg)->errors()->all();
    }

    public static function editPassword($param){
        $rules = [
            'userId'=>'required|numeric',
            'lastIp'=>'required|ip',
            'phone'=>['required','regex:/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/'],
            'password'=>'required|between:6,16',
            'smsCode'=>'required'
        ];

        $msg = [
            'userId.required'=>'用户编号为空',
            'userId.numeric'=>'用户编号格式不对',
            'lastIp.required'=>'IP地址为空',
            'lastIp.ip'=>'IP地址格式不对',
            'phone.required'=>'手机号为空',
            'phone.regex'=>'手机号格式不对',
            'password.required'=>'密码为空',
            'password.between'=>'密码长度小于6位或大于16位',
            'smsCode.required'=>'验证码为空'
        ];
        return Validator::make($param,$rules,$msg)->errors()->all();
    }

    public static function getParentSn($param){
        $rules = [
            'userId'=>'required|numeric'
        ];

        $msg = [
            'userId.required'=>'用户编号为空',
            'userId.numeric'=>'用户编号格式不对'
        ];
        return Validator::make($param,$rules,$msg)->errors()->all();
    }

    public static function getSnInfo($param){
        $rules = [
            'userId'=>'required|numeric',
            'id'=>'required|numeric'
        ];

        $msg = [
            'userId.required'=>'用户编号为空',
            'userId.numeric'=>'用户编号格式不对',
            'id.required'=>'设备编号为空',
            'id.numeric'=>'设备编号格式不对',
        ];
        return Validator::make($param,$rules,$msg)->errors()->all();
    }

    public static function getClassInfo($param){
        $rules = [
            'userId'=>'required|numeric',
        ];

        $msg = [
            'userId.required'=>'用户编号为空',
            'userId.numeric'=>'用户编号格式不对',
        ];
        return Validator::make($param,$rules,$msg)->errors()->all();
    }

    public static function addClass($param){
        $rules = [
            'userId'=>'required|numeric',
            'lastIp'=>'required|ip',
            'name'=>'required'
        ];

        $msg = [
            'userId.required'=>'用户编号为空',
            'userId.numeric'=>'用户编号格式不对',
            'lastIp.required'=>'IP地址为空',
            'lastIp.ip'=>'IP地址格式不对',
            'name.required'=>'班级名为空'
        ];
        return Validator::make($param,$rules,$msg)->errors()->all();
    }

    public static function getClassSnInfo($param){
        $rules = [
            'id'=>'required|numeric',
        ];

        $msg = [
            'id.required'=>'编号为空',
            'id.numeric'=>'编号格式不对',
        ];
        return Validator::make($param,$rules,$msg)->errors()->all();
    }

    public static function queryIdAdmin($param){
        $rules = [
            'userId'=>'required|numeric',
        ];

        $msg = [
            'userId.required'=>'用户编号为空',
            'userId.numeric'=>'用户编号格式不对',
        ];
        return Validator::make($param,$rules,$msg)->errors()->all();
    }

    public static function updateParentSn($param){
        $rules = [
            'userId'=>'required|numeric',
            'lastIp'=>'required|ip',
            'name'=>'required',
            'avatar'=>'required',
        ];
        $msg = [
            'userId.required'=>'用户编号为空',
            'userId.numeric'=>'用户编号格式不对',
            'lastIp.required'=>'IP地址为空',
            'lastIp.ip'=>'IP地址格式不对',
            'name.required'=>'设备名称',
            'avatar.required'=>'设备头像为空',
        ];
        return Validator::make($param,$rules,$msg)->errors()->all();
    }

    public static function updateAvatar($param){
        $rules = [
            'userId'=>'required|numeric',
            'lastIp'=>'required|ip',
            'avatar'=>'required',
        ];
        $msg = [
            'userId.required'=>'用户编号为空',
            'userId.numeric'=>'用户编号格式不对',
            'lastIp.required'=>'IP地址为空',
            'lastIp.ip'=>'IP地址格式不对',
            'avatar.required'=>'设备头像为空',
        ];
        return Validator::make($param,$rules,$msg)->errors()->all();
    }

    public static function querySnInfo($param){
        $rules = [
            'id'=>'required|numeric',
        ];
        $msg = [
            'id.required'=>'编号为空',
            'id.numeric'=>'编号格式不对',
        ];
        return Validator::make($param,$rules,$msg)->errors()->all();
    }

    public static function retrievePassword($param){
        $rules = [
            'mobile'=>['required','regex:/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/'],
            'password'=>'required|between:6,16',
            'smsCode'=>'required'
        ];

        $msg = [
            'mobile.required'=>'手机号为空',
            'mobile.regex'=>'手机号格式不对',
            'password.required'=>'密码为空',
            'password.between'=>'密码长度小于6位或大于16位',
            'smsCode.required'=>'验证码为空'
        ];
        return Validator::make($param,$rules,$msg)->errors()->all();
    }
}